<template>
  <div class="skeleton is-animated" :style="{ width, height }">
    <!-- 1 盒子-->
    <div class="block"></div>
    <!-- 2 闪效果 skeleton 伪元素 --->
  </div>
</template>

<script setup>
import { defineProps } from 'vue'
defineProps({
  width: {
    type: String,
    default: '100px'
  },
  height: {
    type: String,
    default: '100px'
  },
  bg: {
    type: String,
    default: '#e4e4e4'
  }
})
</script>

<style scoped lang="scss">
.skeleton {
  display: inline-block;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  background-color: #e4e4e4;
  .block {
    width: 100%;
    height: 100%;
    border-radius: 2px;
  }
}
.is-animated {
  &::after {
    content: '';
    position: absolute;
    animation: is-animated 1.5s ease 0s infinite;
    top: 0;
    width: 50%;
    height: 100%;
    background: linear-gradient(
      to left,
      rgba(155, 155, 155, 0) 0,
      rgba(155, 155, 155, 0.3) 50%,
      rgba(155, 155, 155, 0) 100%
    );
    transform: skewX(-45deg);
  }
}
@keyframes is-animated {
  0% {
    left: -100%;
  }
  100% {
    left: 120%;
  }
}
</style>
